/**
 * 动态缩放
 */
class dynamicScaling {

	/**缩放层 */
	private static _scalingLayer: eui.Group = new eui.Group();

	public static setScale(width: number, heigth: number) {
		this._scalingLayer.width = width;
		this._scalingLayer.height = heigth;
		this._scalingLayer.anchorOffsetX = width / 2;
		this._scalingLayer.anchorOffsetY = heigth / 2;
	}


    /**
	 * 添加一个对象到缩放层
	 * //建议group
	 */
	public static addScalingObject(obj: egret.DisplayObject): void {
		this._scalingLayer.addChild(obj);
	}

    /**
	 * 从缩放层删除一个对象
	 */
	public static removeScalingObject(obj: egret.DisplayObject): void {
		if (this._scalingLayer.getChildIndex(obj) >= 0)
			this._scalingLayer.removeChild(obj);
		else
			egret.log("无此对象" + obj.name);
	}

	private static scale: number = 1;

	public static get scaleNum(): number {
		return this.scale;
	}

	public static set scaleNum(scale: number) {
		this.scale = scale;
		this.changeScale();
	}

	/**
	 * 改变尺寸
	 * @param{scaleNum 大小}
	 * @param{changeTimer 动画时间}
	 * @param{changePos 锚点坐标{x,y}   无代表地图中心}
	 */
	private static changeScale(): void {
		let user = webNetworkMananger.getInstance().gameSceneRec.User;
		user = webNetworkMananger.getInstance().gameSceneRec.localToGlobal(user.x, user.y);
		this._scalingLayer.x = this._scalingLayer.anchorOffsetX = user.x;
		this._scalingLayer.y = this._scalingLayer.anchorOffsetY = user.y;


		egret.Tween.removeTweens(this._scalingLayer);
		egret.Tween.get(this._scalingLayer)
			.to({ scaleX: this.scale, scaleY: this.scale }, 500)
	}

	public static get dynamicLayer(): eui.Group {
		return this._scalingLayer;
	}
}

class DrawMap {

	/**绘制六边形 */
	public static drawHexagonToGroup(group: eui.Group) {
		for (var t = 0; t < 1; t++) {
			for (var i = 0; i < 1; i++) {
				group.addChild(this.getHexagon(t, i));
			}
		}
	}
	/**绘制线 */
	public static drawLineToGroup(group: eui.Group) {
		let startX = -800;
		let startY = -800;
		let x = -500;
		let y = -500;
		let random = 0;
		while (x < 2500 * 3 / 2) {
			random = Math.floor(Math.random() * 200);
			group.addChild(this.getLine({ x: x + random, y: startY }, { x: x + random, y: 2500 * 3 / 2 }));
			x += random;
		}

		while (y < 2500 * 3 / 2) {
			random = Math.floor(Math.random() * 200);
			group.addChild(this.getLine({ x: startX, y: y + random }, { x: 2500 * 3 / 2, y: y + random }));
			y += random;
		}
	}

	private static operationObject: any = null;

	private static getLine(startPoint, endPoint) {
		this.operationObject = new egret.Shape();
		this.operationObject.graphics.lineStyle(2, 0x00ff00);
		this.operationObject.graphics.moveTo(startPoint.x, startPoint.y);
		this.operationObject.graphics.lineTo(endPoint.x, endPoint.y);
		this.operationObject.graphics.endFill();
		return this.operationObject;
	}

	private static getHexagon(x, y) {
		this.operationObject = new eui.Image();
		this.operationObject.texture = RES.getRes("imageName");
		this.operationObject.width = 10;
		this.operationObject.height = 10;
		this.operationObject.anchorOffsetX = this.operationObject.width / 2;
		this.operationObject.anchorOffsetY = this.operationObject.height / 2;
		this.operationObject.x = x;
		this.operationObject.y = y;
		return this.operationObject

	}
}